'use strict'
// Template version: 1.3.1
// see http://vuejs-templates.github.io/webpack for documentation.

const path = require('path')
const resolve = dir => path.join(__dirname, dir)

module.exports = {
    publicPath: "./",
    configureWebpack: {
      externals: {
        AMap: 'window.AMap',
        AMapUI: 'window.AMapUI' // 高德地图配置
      },
    },
    publicPath: './',
    pages: {
      index: {
        // page 的入口
        entry: 'src/main.js',
        // 模板来源
        template: 'public/index.html',
        // 在 dist/index.html 的输出
        filename: 'index.html',
        // 当使用 title 选项时，
        // template 中的 title 标签需要是 <title><%= htmlWebpackPlugin.options.title %></title>
        title: 'oneapp',
        // 在这个页面中包含的块，默认情况下会包含
        // 提取出来的通用 chunk 和 vendor chunk。
        // chunks: ['chunk-vendors', 'chunk-common', 'index']
      },
      // 当使用只有入口的字符串格式时，
      // 模板会被推导为 `public/subpage.html`
      // 并且如果找不到的话，就回退到 `public/index.html`。
      // 输出文件名会被推导为 `subpage.html`。
    //   subpage: 'src/subpage/main.js'
    },
    dev: {
        baseUrl: './',
        runtimeCompiler: true,
        chainWebpack: config => {
            config.resolve.alias
                .set('@', resolve('src'))
        },
        // Paths
        assetsSubDirectory: 'static',
        assetsPublicPath: '/',
        proxyTable: {
            // "/api": {
            //     target: "http://192.168.0.201:12386", // 要请求的后台地址
            //     ws: true, // 启用websockets
            //     changeOrigin: true, // 是否跨域
            //     pathRewrite: {
            //         "^/api": "/" // 这里理解成用‘/api’代替target里面的地址，后面组件中我们掉接口时直接用api代替
            //     }
            // https://movie.douban.com/j/search_subjects?type=tv&tag=%E7%83%AD%E9%97%A8&page_limit=5&page_start=3
            '/baiduApi': {
                // target: 'http://shuige.wicp.vip/', //访问地址
                target: 'https://movie.douban.com/', //访问地址

                changeOrigin: true,
                secure: false, //只有代理https 地址需要次选项
                pathRewrite: {
                    '^/baiduApi': '/'
                }
            },
            '/baidu': {
                // target: 'http://shuige.wicp.vip/', //访问地址
                target: 'https://www.baidu.com', //访问地址
                

                changeOrigin: true,
                secure: true, //只有代理https 地址需要次选项
                pathRewrite: {
                    '^/baidu': ''
                }
            }
        },

        // Various Dev Server settings
        host: 'localhost', // can be overwritten by process.env.HOST
        port: 8089, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
        autoOpenBrowser: true,
        errorOverlay: true,
        notifyOnErrors: true,
        poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-


        /**
         * Source Maps
         */

        // https://webpack.js.org/configuration/devtool/#development
        devtool: 'cheap-module-eval-source-map',

        // If you have problems debugging vue-files in devtools,
        // set this to false - it *may* help
        // https://vue-loader.vuejs.org/en/options.html#cachebusting
        cacheBusting: true,

        cssSourceMap: true
    },

    build: {
        // Template for index.html
        index: path.resolve(__dirname, '../dist/index.html'),

        // Paths
        assetsRoot: path.resolve(__dirname, '../dist'),
        assetsSubDirectory: 'static',
        assetsPublicPath: '/',

        /**
         * Source Maps
         */

        productionSourceMap: true,
        // https://webpack.js.org/configuration/devtool/#production
        devtool: '#source-map',

        // Gzip off by default as many popular static hosts such as
        // Surge or Netlify already gzip all static assets for you.
        // Before setting to `true`, make sure to:
        // npm install --save-dev compression-webpack-plugin
        productionGzip: false,
        productionGzipExtensions: ['js', 'css'],

        // Run the build command with an extra argument to
        // View the bundle analyzer report after build finishes:
        // `npm run build --report`
        // Set to `true` or `false` to always turn it on or off
        bundleAnalyzerReport: process.env.npm_config_report
    }
}